<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%
	//定时获取住院记录  
	SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
	String nowDate = input.getDesc("nowDate",sdf.format(new Date()));
	String nowEndDa = sdf.format(new Date());
	
	//nowDate = "20160329";
	//nowEndDa = "20180411";
	String startDate = nowDate+"00:00:00";
	String endDate = nowEndDa+"24";

	String sql = "select new map(syxh as syxh , patid as patid , mzh as mzh ,blh as blh ,hzxm as hzxm , sfzh as sfzh , sex as sex , ksdm as ksdm ,bqdm as bqdm , ysdm as ysdm , cwdm as cwdm , brzt as brzt , ybdm as ybdm "
	+" ,lrrq as lrrq ,ryrq as ryrq , rqrq as rqrq , cyrq as cyrq , cqrq as cqrq , wzjb as wzjb , ryfs as ryfs ,cyfs as cyfs, memo as memo , zddm as zddm , cyzdmc as cyzdmc , ssdm1 as ssdm1 , ssdm2 as ssdm2) from ZY_BRSYK  " 
	+" where rqrq != null and rqrq >='"+ startDate + "' and rqrq<='"+endDate+"'";
	

	List<Map> list = QBuilder.db("basedb").queryHql(sql);
	
	for(Map map : list){
		map.put("create_time",sdf1.format(new Date()));
	}
	List<Map> oldList = QBuilder.db("basedb").queryHql("select new map(id as id ) from ZY_BRSYK where create_time='"+sdf1.format(new Date())+"'");
	if(oldList != null && oldList.size() > 0){
		//已经存在数据
		return;
	}
	
	DBTools.db("localdb").addItem("ZY_BRSYK",list);
	
	
	//更新可是
	QBuilder.db("localdb").execHQL("delete from his_dept");
	List<Map> list2 = QBuilder.db("basedb").queryHql("select new map(id as id , name as name ,py as py,yjks_id as yjks_id ,yjks_mc as yjks_mc , ejks_id as ejks_id ,ejks_mc as ejks_mc , yydm as yydm ) from his_dept");
	DBTools.db("localdb").addItem("his_dept",list2);
	
	Message msg = new Message();
	

	out.println(msg);
%>